<template>
  <div  class="wrapper">
    <BreakSpace label="基本信息" :containerStyle="{ marginBottom: '15px' }" />
    <div style="height:300px">
      <FormPanel
        ref="from"
        :list="initForm"
        :cols="3"
        :formType="value.type"
        :labelWidth="120"
        :isSubmitBtn="false"
        :collapse="false"
        @formChange="changeHandle"
      />
    </div>

    <BreakSpace label="配件信息" :containerStyle="{ marginBottom: '15px' }" />
    <FilterTable
      height="auto"
      ref="tablePeij"
      :columns="partColumns"
      :isSelectColumn="isSelectColumn"
      selectionType="single"
      :isMemoryPagination="true"
      :onSyncTableData="syncPjFun"
      :datakey="'records'"
      :isToperInfo="false"
      :isExportExcel2="true"
      :exportFileName="'退货配件信息.xlsx'"
      :onColumnsChange="partColumns => (this.partColumns = partColumns)"
      columnsRef="notification_maintain_info_02"
    >
    </FilterTable>

    <BreakSpace label="审核信息" :containerStyle="{ marginBottom: '15px' }" />
    <approveHistory v-model="approvalparams" />

    <div class="dialogBottmView">
      <el-button @click="closeDialog('closeDialog')">关 闭</el-button>
    </div>
  </div>
</template>

<script>
import { getFileGroup } from '@/api/partsmanage/common/file';
import {getPartsByReturnID,getPartInfo} from '@/api/partsmanage/saleReturnManage/index';
import approveHistory from '../../components/approveHistory';
import moment from 'moment';
import { dictionary } from '@/utils/dictMixin';
export default {
  name: "detailInfo",
  mixins: [dictionary],
  props:{
    value: {
      type: Object,
      data: Object,
      required: true
    },
  },
  components:{
    approveHistory
  },
  data() {
    return {
      type: this.value.type,
      initForm : this.initFormFun(),
      partColumns: this.creatHeaderPartRoleColumns(),
      partList: [],
      isSelectColumn: false,
      visibleImportPeij: false,
      initPartData: {},
      visiblePart: false,
      visiblePartOrder: false,
      visiblePartsGroup: false,
      oderseach: false,
      formData:{},
      searchData: {},
      returnID: '',
      saveData: {
        bkpzsl: 0,
        bkztze: 0,
        partList: []
      },
      djzt: null,
      loadingFlag:false,
      approvalparams: {}
    };
  },
  created() {
    this.init(this.value.data)
  },
  methods: {
    init(data) {
      this.returnID = data.id
      var initdata = {
        id: data.id,
        bkthlx: data.bkthlx,
        ownerCode: data.ownerCode
      }
      this.djzt = data.bkxtzt
      getPartsByReturnID(initdata).then(response => {
        var list = response.data
        if(response.resultCode === 200){
          this.$nextTick(()=>{
            this.$refs.tablePeij.EXECUTE_INSERT(list)
          })
        }
      })
      this.approvalparams.xtspid = data.id
      this.approvalparams.xtsplx = 'tt_sale_return'
      this.initForm.forEach(x => {
        if (x.fieldName === 'created_at') {
          x.initialValue = moment(data.createdAt).format('YYYY-MM-DD HH:mm:ss');
        } else if (x.fieldName === 'bkthlx'){
          x.initialValue = data[x.fieldName];
          if(data[x.fieldName] === 50041004 || data[x.fieldName] === 50041005){
            this.oderseach = true
          }
        } else {
          x.initialValue = data[x.fieldName];
        }
      });
      getFileGroup({ "xtdjid": this.returnID, "xtfjlx": "5" }).then(response => {
        var fileList = response.data.records
        this.initForm.forEach(x => {
          if (x.fieldName === 'wayFiles') {
            x.initialValue = fileList
          }
        })
      })
    },
    initFormFun(){
      return [
        {
          type: 'INPUT',
          label: '退货单号',
          fieldName: 'bkxtdh',
          disabled: true,
          hidden: this.value.type === 'add'
        },
        {
          type: 'SELECT',
          label: '退货类型',
          fieldName: 'bkthlx',
          placeholder: '请选择',
          clearable: false,
          initialValue: 50041001,
          itemList: this.createDictList('5004'),
          disabled: true
        },
        {
          type: 'INPUT',
          label: '创建日期',
          fieldName: 'created_at',
          placeholder: '请输入',
          initialValue:  moment(new Date()).format('YYYY-MM-DD HH:mm:ss'),
          disabled: true
        },
        {
          type: 'INPUT',
          label: '经办人',
          fieldName: 'bkjbry',
          placeholder: '请输入',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '经办人电话',
          fieldName: 'bkrydh',
          placeholder: '请输入',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '采购单号',
          fieldName: 'bkysdj',
          disabled: true,
        },
        {
          type: 'TEXT_AREA',
          label: '退货原因',
          fieldName: 'bkxtly',
          disabled: true,
          selfCols:3
        },
        {
          type: 'TEXT_AREA',
          label: '审核意见',
          fieldName: 'xtspnr',
          disabled: true,
          selfCols:3
        },
        {
          selfCols: 3,
          type: 'UPLOAD_FILE',
          label: '上传文件',
          fieldName: 'wayFiles',
          placeholder: '上传文件...',
          initialValue: '',
          disabled:true,
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 1,
            tipText: '（支持：PDF、RAR、JPG格式）'
          }
        }
      ]
    },
    creatHeaderPartRoleColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          fixed: 'left',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        { title: '厂家发货仓库名称', fixed: 'left', dataIndex: 'bsckmc', sorter: true },
        { title: '配件id', dataIndex: 'bjpjid', hidden: true },
        { title: '配件代码', fixed: 'left', dataIndex: 'bjxmbh', sorter: true },
        { title: '配件名称', fixed: 'left', dataIndex: 'bjzwmc', sorter: true },
        // { title: '可退货数量', dataIndex: 'pjktsl', sorter: true },
        // { title: '库存数量', dataIndex: 'pjkykc', sorter: true },
        { title: '采购单价', dataIndex: 'jjhdj', sorter: true },
        { title: '折扣率', dataIndex: 'pjzkl', sorter: true },
        { title: '折扣后单价', dataIndex: 'bsxszk', sorter: true },
        // { title: '采购单号', dataIndex: 'xsddhm', sorter: true },
        {
          title: '退货数量',
          dataIndex: 'bkthsl',
          sorter: true
        },
        { title: '批准退货数量', dataIndex: 'bkshsl', sorter: true },
        { title: '实际退货数量', dataIndex: 'bksjsl', sorter: true },
        { title: '实际退货金额', dataIndex: 'bkzonj', sorter: true },
        { title: '配件属性', dataIndex: 'bjpjsx', sorter: true, render: props => { return <span>{this.createDictText(props.row.bjpjsx, '5000')}</span>; } },
        { title: '状态',
          editType: 'select',
          dataIndex: 'bkthzt',
          editItems: [{text: '通过', value: 1 },{text: '拒绝', value: 2 }]
        },
        { title: '拒绝原因', dataIndex: 'bkjjyy', sorter: true }
      ];
    },
    changeHandle(val){
      this.saveData=val
    },
    syncPjFun(details){
      this.formData.details = details
    },
    //取消操作
    closeDialog(type) {
      this.$emit('close', type);
    }
  }
};
</script>
<style scoped>
.wrapper {
  height: calc(100vh - 110px);
}
</style>
